package cn.appsys.controller.developer;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;
import com.sun.corba.se.impl.orbutil.closure.Constant;

import cn.appsys.pojo.AppCategory;
import cn.appsys.pojo.AppInfo;
import cn.appsys.pojo.AppVersion;
import cn.appsys.pojo.DataDictionary;
import cn.appsys.pojo.DevUser;
import cn.appsys.service.developer.AppCategory.AppCategoryService;
import cn.appsys.service.developer.AppInfo.AppInfoService;
import cn.appsys.service.developer.AppInfo.AppInfoServiceImpl;
import cn.appsys.service.developer.AppVersion.AppVersionService;
import cn.appsys.service.developer.DataDictionary.DataDictionaryService;
import cn.appsys.service.developer.DevUser.DevUserService;
import cn.appsys.tools.Constants;
import cn.appsys.tools.PageSupport;


@Controller
@RequestMapping("/dev")
public class DevController {

	private Logger logger = Logger.getLogger(DevController.class);

	@Resource
	DevUserService devUserService;
	@Resource
	AppInfoService appInfoService;
	@Resource
	DataDictionaryService dataDictionaryService;
	@Resource
	AppCategoryService appCategoryService;
	@Resource
	AppVersionService appVersionService;

	@RequestMapping(value="/login")
	public String  DevShow(){
		logger.debug("=================>hello,DevController!");
		return "devlogin";
	}

	//开发真登陆
	@RequestMapping(value="/login/flatfrom/main")
	public String DevMain(String devCode,String devPassword,Model model,HttpSession session){
		DevUser devUser = new DevUser();
		devUser = devUserService.devUserlogin(devCode, devPassword);
		if(devUser == null){
			model.addAttribute("error", "用户名或密码不正确！");
			return "devlogin";
		}else{
			session.setAttribute(Constants.DEVUSER_SESSION, devUser);
		}
		return "developer/main";
	}
	//list
	@RequestMapping(value="/flatform/app/list")
	public String Devlist(Model model,
			@RequestParam(value="querySoftwareName",required=false )String querySoftwareName,
			@RequestParam(value="queryStatus",required=false )String queryStatus,
			@RequestParam(value="queryFlatformId",required=false )String queryFlatformId,
			@RequestParam(value="queryCategoryLevel1",required=false )String queryCategoryLevel1,
			@RequestParam(value="queryCategoryLevel2",required=false )String queryCategoryLevel2,
			@RequestParam(value="queryCategoryLevel3",required=false )String queryCategoryLevel3,
			@RequestParam(value="pageIndex",required=false ) String pageIndex,
			HttpSession session){

		List<AppInfo> AppInfoList = new ArrayList<AppInfo>();
		AppInfo app = new AppInfo();
		Integer _queryStatus = null;
		Integer _queryFlatformId = null;
		Integer _queryCategoryLevel1 = null;
		Integer _queryCategoryLevel2 = null;
		Integer _queryCategoryLevel3 = null;
		//设置页面容量
		int pageSize = Constants.pageSize;
		//当前页码
		int currentPageNo = 1;
		//当前用户id
		DevUser devId = (DevUser)session.getAttribute(Constants.DEVUSER_SESSION);
		if(querySoftwareName == null){
			querySoftwareName = "";
		}
		app.setSoftwareName(querySoftwareName);
		if(queryStatus != null && queryStatus != ""){
			_queryStatus = Integer.parseInt(queryStatus);
		}
		if(queryFlatformId != null && queryFlatformId != ""){
			_queryFlatformId = Integer.parseInt(queryFlatformId);
		}
		if(queryCategoryLevel1 != null && queryCategoryLevel1 != ""){
			_queryCategoryLevel1 = Integer.parseInt(queryCategoryLevel1);
		}
		if(queryCategoryLevel2 != null && queryCategoryLevel2 != ""){
			_queryCategoryLevel2 = Integer.parseInt(queryCategoryLevel2);
		}
		if(queryCategoryLevel3 != null && queryCategoryLevel3 != ""){
			_queryCategoryLevel3 = Integer.parseInt(queryCategoryLevel3);
		}
		app.setStatus(_queryStatus);
		app.setFlatformId(_queryFlatformId);
		app.setCategoryLevel1(_queryCategoryLevel1);
		app.setCategoryLevel2(_queryCategoryLevel2);
		app.setCategoryLevel3(_queryCategoryLevel3);
		app.setDevId(devId.getId());

		if(pageIndex != null){
			try {
				currentPageNo = Integer.valueOf(pageIndex);
			} catch (Exception e) {
				return "error";
			}
		}
		//总数量
		int totalCount = appInfoService.appInfoCount(app);
		//总页数
		PageSupport pages=new PageSupport();
		pages.setCurrentPageNo(currentPageNo);
		pages.setPageSize(pageSize);
		pages.setTotalCount(totalCount);

		int totalPageCount = pages.getTotalPageCount();

		//控制首页和尾页
		if(currentPageNo < 1){
			currentPageNo = 1;
		}else if(currentPageNo > totalPageCount){
			currentPageNo = totalPageCount;
		}
		app.setCurrentPageNo((currentPageNo-1)*pageSize);
		app.setPageSize(pageSize);
		AppInfoList = appInfoService.appInfoList(app);
		model.addAttribute("appInfoList", AppInfoList);
		List<DataDictionary> statusList = dataDictionaryService.getAppStatusList();
		model.addAttribute("statusList", statusList);
		List<DataDictionary> flatFormList = dataDictionaryService.getAppFlatformList();
		model.addAttribute("flatFormList", flatFormList);
		List<AppCategory> categoryLevel1List = appCategoryService.getAppCategorylsit1();
		model.addAttribute("categoryLevel1List", categoryLevel1List);
		List<AppCategory> categoryLevel2List = null;
		//二级分类列表和三级分类列表---回显
		if(queryCategoryLevel2 != null && !queryCategoryLevel2.equals("")){
			categoryLevel2List = getCategoryList(_queryCategoryLevel1.toString());
			model.addAttribute("categoryLevel2List", categoryLevel2List);
		}
		List<AppCategory> categoryLevel3List = null;
		if(queryCategoryLevel3 != null && !queryCategoryLevel3.equals("")){
			categoryLevel3List = getCategoryList(_queryCategoryLevel2.toString());
			model.addAttribute("categoryLevel3List", categoryLevel3List);
		}
		model.addAttribute("pages", pages);
		model.addAttribute("querySoftwareName", querySoftwareName);
		model.addAttribute("queryStatus", queryStatus);
		model.addAttribute("queryFlatformId", queryFlatformId);
		model.addAttribute("queryCategoryLevel1", queryCategoryLevel1);
		model.addAttribute("queryCategoryLevel2", queryCategoryLevel2);
		model.addAttribute("queryCategoryLevel3", queryCategoryLevel3);
		return "developer/appinfolist";
	}

	/**
	 * 根据parentId查询出相应的分类级别列表
	 * @param pid
	 * @return
	 */
	@RequestMapping(value="/categorylevellist.json",method=RequestMethod.GET)
	@ResponseBody
	public List<AppCategory> getAppCategoryList (@RequestParam String pid){
		logger.debug("/getAppCategoryList pid ============ " + pid);
		if(pid.equals("")) pid = null;
		return getCategoryList(pid);
	}
	/**
	 * 根据parentId查询出相应的分类级别列表
	 * @param pid
	 * @return
	 */
	public List<AppCategory> getCategoryList (String pid){
		List<AppCategory> categoryLevelList = null;
		try {
			categoryLevelList = appCategoryService.getAppCategoryListByParentId(pid==null?null:Integer.parseInt(pid));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return categoryLevelList;
	}
	@RequestMapping("/datadictionarylist.json")
	@ResponseBody
	public List<DataDictionary> DataDictionaryflatFormList(){
		List<DataDictionary> flatFormList = null;
		try {
			flatFormList = dataDictionaryService.getAppFlatformList();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flatFormList;
	}

	@RequestMapping("getCategoryList1.json")
	@ResponseBody
	public List<AppCategory> getCategoryList1(){
		List<AppCategory> getCategoryList1 = null;
		try {
			getCategoryList1 = appCategoryService.getAppCategorylsit1();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return getCategoryList1;
	}
	@RequestMapping("apkexist.json")
	@ResponseBody
	public Object YouAPKName(String APKName){
		HashMap<String, String> resultMap = new HashMap<String ,String>();
		if(APKName == null || APKName.equals("")){
			resultMap.put("APKName", "empty");
		}else{
			AppInfo app = null;
			app = appInfoService.appInfoAPKName(APKName);
			if(app == null){
				resultMap.put("APKName", "noexist");
			}else{
				resultMap.put("APKName", "exist");
			}
		}
		return JSONArray.toJSONString(resultMap);
	}

	@RequestMapping("/flatform/app/appinfoadd")
	public String appadd(Model model){
		return "developer/appinfoadd";
	}

	@RequestMapping(value="/appinfoaddsave",method=RequestMethod.POST)
	public String appInfoaddsave(AppInfo appInfo,
			HttpSession session,
			HttpServletRequest request,
			@RequestParam(value="a_logoPicPath",required=false)MultipartFile attach){
		String logoPicPath = null;
		String logoPicPath0 = null;
		String fileUploadError = "fileUploadError";
		boolean flag = true;
		if(!attach.isEmpty()){
			String path = request.getSession().getServletContext()
					.getRealPath("statics"+File.separator+"uploadfiles");
			logger.info("uploadFile path =================> "+path);
			String oldFileName = attach.getOriginalFilename();//原文件名
			logger.info("uploadFile oldFileName =================> "+oldFileName);
			String prefix = FilenameUtils.getExtension(oldFileName);;//原文件后缀
			logger.debug("uploadFile prefix =================> "+prefix);
			int filesize = 500000000;
			logger.debug("uploadFile size =================> "+attach.getSize());
			if(attach.getSize() > filesize){//上传大小不得超过5M
				request.setAttribute(fileUploadError, " * 上传大小不得超过 5M");
				return "developer/appinfoadd";
			}else if(prefix.equalsIgnoreCase("jpg")
					|| prefix.equalsIgnoreCase("png")
					|| prefix.equalsIgnoreCase("jpeg")
					|| prefix.equalsIgnoreCase("pneg")){
				String fileName = appInfo.getAPKName()+".jpg";
				File targetFile = new File(path,fileName);
				if(!targetFile.exists()){
					targetFile.mkdirs();
				}
				//保存
				try {
					attach.transferTo(targetFile);
				} catch (Exception e) {
					e.printStackTrace();
					request.setAttribute(fileUploadError, " * 上传失败！");
					flag = false;
				}
				logoPicPath = path+File.separator+fileName;
				String[] logoPicPaths=logoPicPath.replaceAll("\\\\", "/").split("appsys");
				logoPicPath0 ="/appsys"+logoPicPaths[1];
				logger.debug("logoPicPath:"+logoPicPath0);
			}else{
				request.setAttribute(fileUploadError, " * 上传图片格式不正确");
				flag = false;
			}
		}
		if(flag){
			appInfo.setLogoLocPath(logoPicPath);
			appInfo.setCreatedBy(((DevUser) session.getAttribute(Constants.DEVUSER_SESSION)).getId());
			appInfo.setDevId(((DevUser) session.getAttribute(Constants.DEVUSER_SESSION)).getId());
			appInfo.setCreationDate(new Date());
			appInfo.setLogoPicPath(logoPicPath0);
			if(appInfoService.appInfoadd(appInfo)){
				return "redirect:/dev/flatform/app/list";
			}
		}
		return "developer/appinfoadd";
	}

	@RequestMapping(value="/appinfomodify")
	public String appinfomodify(String id,Model model){
		AppInfo appInfo = appInfoService.appInfoById(Integer.parseInt(id));
		model.addAttribute("appInfo", appInfo);
		return "developer/appinfomodify";
	}

	@RequestMapping(value="appInfo/delfile.json",method=RequestMethod.GET)
	@ResponseBody
	public Object delfile(String id){
		HashMap<String, String> resultMap = new HashMap<String ,String>();
		AppInfo appInfo = appInfoService.appInfoById(Integer.parseInt(id));
		File fileId = new File(appInfo.getLogoLocPath());
		if(fileId.delete()){
			if(appInfoService.appInfoBylogoPicPathDel(Integer.parseInt(id))){
				resultMap.put("result", "success");
			}else{
				resultMap.put("result", "failed");
			}
		}else{
			resultMap.put("result", "failed");
		}
		return JSONArray.toJSONString(resultMap);
	}

	@RequestMapping(value="/appinfomodifysave",method=RequestMethod.POST)
	public String appinfomodifysave(AppInfo appInfo,
			HttpSession session,
			HttpServletRequest request,
			@RequestParam(value="attach",required=false)MultipartFile attach){
		String logoPicPath = null;
		String logoPicPath0 = null;
		String fileUploadError = "fileUploadError";
		boolean flag = true;
		if(!attach.isEmpty()){
			String path = request.getSession().getServletContext()
					.getRealPath("statics"+File.separator+"uploadfiles");
			logger.info("uploadFile path =================> "+path);
			String oldFileName = attach.getOriginalFilename();//原文件名
			logger.info("uploadFile oldFileName =================> "+oldFileName);
			String prefix = FilenameUtils.getExtension(oldFileName);;//原文件后缀
			logger.debug("uploadFile prefix =================> "+prefix);
			int filesize = 500000000;
			logger.debug("uploadFile size =================> "+attach.getSize());
			if(attach.getSize() > filesize){//上传大小不得超过5M
				request.setAttribute(fileUploadError, " * 上传大小不得超过 5M");
				return "developer/appinfomodify";
			}else if(prefix.equalsIgnoreCase("jpg")
					|| prefix.equalsIgnoreCase("png")
					|| prefix.equalsIgnoreCase("jpeg")
					|| prefix.equalsIgnoreCase("pneg")){
				String fileName = appInfo.getAPKName()+".jpg";
				File targetFile = new File(path,fileName);
				if(!targetFile.exists()){
					targetFile.mkdirs();
				}
				//保存
				try {
					attach.transferTo(targetFile);
				} catch (Exception e) {
					e.printStackTrace();
					request.setAttribute(fileUploadError, " * 上传失败！");
					flag = false;
				}
				logoPicPath = path+File.separator+fileName;
				String[] logoPicPaths=logoPicPath.replaceAll("\\\\", "/").split("appsys");
				logoPicPath0 ="/appsys"+logoPicPaths[1];
				logger.debug("logoPicPath:"+logoPicPath0);
			}else{
				request.setAttribute(fileUploadError, " * 上传图片格式不正确");
				flag = false;
			}
		}
		if(flag){
			appInfo.setLogoLocPath(logoPicPath);
			appInfo.setModifyBy(((DevUser) session.getAttribute(Constants.DEVUSER_SESSION)).getId());
			appInfo.setModifyDate(new Date());
			appInfo.setLogoPicPath(logoPicPath0);
			if(appInfoService.appInfomodify(appInfo)){
				return "redirect:/dev/flatform/app/list";
			}
		}
		return "developer/appinfomodify";
	}

	@RequestMapping(value="/appversionadd")
	public String appversionadd(String id,Model model){
		List<AppVersion> appVersionList = appVersionService.appVersionList(Integer.parseInt(id));
		model.addAttribute("appId", id);
		model.addAttribute(appVersionList);
		return "developer/appversionadd";
	}
	@RequestMapping(value="/addversionsave",method = RequestMethod.POST)
	public String addversionsave(AppVersion appVersion,
			String appId,
			HttpSession session,
			HttpServletRequest request,
			@RequestParam(value="a_downloadLink",required=false)MultipartFile attach) throws Exception{
		String apkFileName = null;
		String downloadLink = null;
		String fileUploadError = "fileUploadError";
		String dPath = null;
		boolean flag = true;
		AppInfo appInfo = appInfoService.appInfoById(Integer.parseInt(appId));
		if(!attach.isEmpty()){
			String path = request.getSession().getServletContext()
					.getRealPath("statics"+File.separator+"uploadfiles");
			logger.info("uploadFile path =================> "+path);
			String oldFileName = attach.getOriginalFilename();//原文件名
			logger.info("uploadFile oldFileName =================> "+oldFileName);
			String prefix = FilenameUtils.getExtension(oldFileName);;//原文件后缀
			logger.debug("uploadFile prefix =================> "+prefix);
			long filesize = 999999999;
			logger.debug("uploadFile size =================> "+attach.getSize());
			if(attach.getSize() > filesize){//上传大小不得超过5M
				request.setAttribute(fileUploadError, " * 上传大小不得超过 5M");
				return "developer/appversionadd";
			}else if(prefix.equalsIgnoreCase("apk")){
				String fileName = appInfo.getAPKName()+"-"+appVersion.getVersionNo()+".apk";
				File targetFile = new File(path,fileName);
				if(!targetFile.exists()){
					targetFile.mkdirs();
				}
				//保存
				try {
					attach.transferTo(targetFile);
				} catch (Exception e) {
					e.printStackTrace();
					request.setAttribute(fileUploadError, " * 上传失败！");
					flag = false;
				}
				dPath = path+File.separator+fileName;
				String[] logoPicPaths=dPath.replaceAll("\\\\", "/").split("appsys");
				String[] logoPicPathss = logoPicPaths[1].split("uploadfiles/");
				apkFileName = logoPicPathss[1];
				logger.debug("apkFileName:"+apkFileName);
				downloadLink ="/appsys"+logoPicPaths[1];
				logger.debug("downloadLink:"+downloadLink);
			}else{
				request.setAttribute(fileUploadError, " * 上传文件格式不正确");
				flag = false;
			}
		}
		if(flag){
			appVersion.setApkLocPath(dPath);
			appVersion.setCreatedBy(((DevUser) session.getAttribute(Constants.DEVUSER_SESSION)).getId());
			appVersion.setCreationDate(new Date());
			appVersion.setDownloadLink(downloadLink);
			appVersion.setApkFileName(apkFileName);
			if(appVersionService.appsysadd(appVersion)){
				return "redirect:/dev/flatform/app/list";
			}
		}
		return "developer/appversionadd";
	}

	@RequestMapping(value="/appversionmodify")
	public String appversionmodify(String vid,String aid,Model model){
		List<AppVersion> appVersionList = appVersionService.appVersionList(Integer.parseInt(aid));
		model.addAttribute(appVersionList);
		AppVersion appVersion = appVersionService.appVersionById(Integer.parseInt(vid));
		model.addAttribute(appVersion);
		return "developer/appversionmodify";
	}

	@RequestMapping(value="appVersion/delfile.json",method=RequestMethod.GET)
	@ResponseBody
	public Object appVersiondelfile(String id){
		AppVersion appVersion = appVersionService.appVersionById(Integer.parseInt(id));
		HashMap<String, String> resultMap = new HashMap<String ,String>();
		File fileId = new File(appVersion.getApkLocPath());
		if(fileId.delete()){
			if(appVersionService.appVersionFileDel(Integer.parseInt(id))){
				resultMap.put("result", "success");
			}else{
				resultMap.put("result", "failed");
			}
		}else{
			resultMap.put("result", "failed");
		}
		return JSONArray.toJSONString(resultMap);
	}

	@RequestMapping(value="appversionmodifysave",method=RequestMethod.POST)
	public String appversionmodifysave(AppVersion appVersion,
			String appId,
			HttpSession session,
			HttpServletRequest request,
			@RequestParam(value="attach",required=false)MultipartFile attach) throws Exception{
		String apkFileName = null;
		String downloadLink = null;
		String fileUploadError = "fileUploadError";
		String dPath = null;
		boolean flag = true;
		AppInfo appInfo = appInfoService.appInfoById(Integer.parseInt(appId));
		if(!attach.isEmpty()){
			String path = request.getSession().getServletContext()
					.getRealPath("statics"+File.separator+"uploadfiles");
			logger.info("uploadFile path =================> "+path);
			String oldFileName = attach.getOriginalFilename();//原文件名
			logger.info("uploadFile oldFileName =================> "+oldFileName);
			String prefix = FilenameUtils.getExtension(oldFileName);;//原文件后缀
			logger.debug("uploadFile prefix =================> "+prefix);
			long filesize = 999999999;
			logger.debug("uploadFile size =================> "+attach.getSize());
			if(attach.getSize() > filesize){//上传大小不得超过5M
				request.setAttribute(fileUploadError, " * 上传大小不得超过 5M");
				return "developer/appversionadd";
			}else if(prefix.equalsIgnoreCase("apk")){
				String fileName = appInfo.getAPKName()+"-"+appVersion.getVersionNo()+".apk";
				File targetFile = new File(path,fileName);
				if(!targetFile.exists()){
					targetFile.mkdirs();
				}
				//保存
				try {
					attach.transferTo(targetFile);
				} catch (Exception e) {
					e.printStackTrace();
					request.setAttribute(fileUploadError, " * 上传失败！");
					flag = false;
				}
				dPath = path+File.separator+fileName;
				String[] logoPicPaths=dPath.replaceAll("\\\\", "/").split("appsys");
				String[] logoPicPathss = logoPicPaths[1].split("uploadfiles/");
				apkFileName = logoPicPathss[1];
				logger.debug("apkFileName:"+apkFileName);
				downloadLink ="/appsys"+logoPicPaths[1];
				logger.debug("downloadLink:"+downloadLink);
			}else{
				request.setAttribute(fileUploadError, " * 上传文件格式不正确");
				flag = false;
			}
		}
		if(flag){
			appVersion.setApkLocPath(dPath);
			appVersion.setCreatedBy(((DevUser) session.getAttribute(Constants.DEVUSER_SESSION)).getId());
			appVersion.setCreationDate(new Date());
			appVersion.setDownloadLink(downloadLink);
			appVersion.setApkFileName(apkFileName);
			if(appVersionService.appVersionmodify(appVersion)){
				return "redirect:/dev/flatform/app/list";
			}
		}
		return "developer/appversionmodify";
	}

	@RequestMapping(value="/appview")
	public String appview(String id,Model model){
		AppInfo appInfo = appInfoService.appInfoById(Integer.parseInt(id));
		model.addAttribute(appInfo);
		List<AppVersion> appVersionList = appVersionService.appVersionList(Integer.parseInt(id));
		model.addAttribute(appVersionList);
		return "developer/appinfoview";
	}

	@RequestMapping(value="delapp.json",method=RequestMethod.GET)
	@ResponseBody
	public Object delapp(String id){
		HashMap<String, String> resultMap = new HashMap<String ,String>();
		if(appInfoService.appInfoById(Integer.parseInt(id)) == null){
			resultMap.put("delResult", "notexist");
		}else{
			List<AppVersion> appversion = appVersionService.appVersionList(Integer.parseInt(id));
			boolean flag = false;
			for (AppVersion appV : appversion) {
				if(appV.getApkLocPath() != null){
					File fileId = new File(appV.getApkLocPath());
					if(fileId.delete()){
						flag = true;
					}else{
						flag = false;
					}
				}else{
					flag = true;
				}
			}
			if(flag){
				if(appVersionService.appVersiondel(Integer.parseInt(id))){
					AppInfo appInfo = appInfoService.appInfoById(Integer.parseInt(id));
					if(appInfo.getLogoLocPath() != null){
						File fileId = new File(appInfo.getLogoLocPath());
						if(fileId.delete()){
							if(appInfoService.appInfodel(Integer.parseInt(id))){
								resultMap.put("delResult", "true");
							}else{
								resultMap.put("delResult", "false");
							}
						}else{
							resultMap.put("delResult", "false");
						}
					}else{
						if(appInfoService.appInfodel(Integer.parseInt(id))){
							resultMap.put("delResult", "true");
						}else{
							resultMap.put("delResult", "false");
						}
					}
				}else{
					resultMap.put("delResult", "false");
				}
			}else{
				resultMap.put("delResult", "false");
			}
		}
		return resultMap;
	}
	
	@RequestMapping(value="/{appid}/sale",method=RequestMethod.PUT)
	@ResponseBody
	public Object sale(@PathVariable String appid,HttpSession session){
		HashMap<String, String> resultMap = new HashMap<String ,String>();
		Integer appIdInteger = 0;
		try {
			appIdInteger = Integer.parseInt(appid);
		} catch (Exception e) {
			appIdInteger = 0;
		}
		resultMap.put("errorCode", "0");
		if(appIdInteger > 0){
			try{
				DevUser devUser = (DevUser) session.getAttribute(Constants.DEVUSER_SESSION);
				AppInfo appInfo = new AppInfo();
				appInfo.setId(appIdInteger);
				appInfo.setModifyBy(devUser.getId());
				if(appInfoService.appsysUpdateSaleStatusByAppId(appInfo)){
					resultMap.put("resultMsg", "success");
				}else{
					resultMap.put("resultMsg", "failed");
				}
			}catch (Exception e) {
				resultMap.put("errorCode", "exception000001");
			}
		}else{
			resultMap.put("errorCode", "param000001");
		}
		return resultMap;
	}
	
	@RequestMapping("/logout")
	public String logout(HttpSession session){
		session.removeAttribute(Constants.DEVUSER_SESSION);
		return "redirect:/dev/login";
	}
}
